<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>挖坑</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <button onclick="resetEdit()">重新绘制挖坑</button>
        <button onclick="editingCurrent()">编辑当前挖坑</button>
    </div>
    <script>

        /** -----------------------------------------地球创建----------------------------------------------------**/

        // Vue中引入方式：import { ESObjectsManager } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';

        const { ESObjectsManager } = XE2['esobjs-xe2-plugin-main']
        const objm = new ESObjectsManager();
        window.g_objm = objm;

        // 创建Cesium视口
        const viewer = objm.createCesiumViewer({
            "domid": document.getElementById("app")
        })
        // 监听视口状态
        viewer.statusChanged.don(status => {
            if (status == 'Created') {
                // 视口创建完成，飞到初始视角位置
                objm.activeViewer.flyIn([108.96299571058906, 34.21678028533886, 646.936464988799], [307.19168576953393, -31.653922742502324, 0.0005275461534735532], 3)
            }
        })

        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 18,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });

        //添加3DTileset
        const ES3DTileset = objm.createSceneObjectFromJson({
            "id": "c2c8311e-6e50-47a2-b764-1c82f2d0e256",
            "type": "ES3DTileset",
            "name": "ES3DTileset",
            "allowPicking": true,
            "url": "https://www.pipeser.com/cesiumlab/G7qC5vBk/tileset.json"
        })


        /**-----------------------------根据类（Class）创建一个ESExcavate挖坑对象-------------------------------**/

        // Vue中引入方式：import { ESExcavate } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';
        const { ESExcavate } = XE2['esobjs-xe2-plugin-main']
        const excavateObject = objm.createSceneObject(ESExcavate)
        //设置挖坑的3dtileset对象的id
        excavateObject.targetID = ES3DTileset.id
        // 多边形顶点数组
        excavateObject.points = [
            [
                108.95948309393542,
                34.219364886363216,
                424.8491858720023
            ],
            [
                108.9598404329272,
                34.21845160868921,
                425.20516531707966
            ],
            [
                108.96065118084383,
                34.218816898311296,
                420.6107390620669
            ],
            [
                108.96056692677261,
                34.219509267618825,
                433.8303881964455
            ]
        ]


        // 重新绘制
        function resetEdit() {
            excavateObject.editing = false
            excavateObject.points = []
            excavateObject.editing = true
        }

        // 编辑当前挖洞
        function editingCurrent() {
            // 开启编辑
            excavateObject.editing = true
        }


    </script>

    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>